<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-fcntl.html" />
<link rel="prev" href="module-tty.html" />
<link rel="parent" href="unix.html" />
<link rel="next" href="module-fcntl.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>16.9 pty -- Pseudo-terminal utilities</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="16.8 tty  "
  href="module-tty.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="16. unix Specific Services"
  href="unix.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="16.10 fcntl  "
  href="module-fcntl.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-tty.html">16.8 tty  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="unix.html">16. Unix Specific Services</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-fcntl.html">16.10 fcntl  </a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION0018900000000000000000">
16.9 <tt class="module">pty</tt> --
         Pseudo-terminal utilities</a>
</h1>
<a name="module-pty"></a>  
<p class="availability">Availability: <span
 class="platform">IRIX, Linux</span>.</p>

<p>
The <tt class="module">pty</tt> module defines operations for handling the
pseudo-terminal concept: starting another process and being able to
write to and read from its controlling terminal programmatically.

<p>
Because pseudo-terminal handling is highly platform dependant, there
is code to do it only for SGI and Linux. (The Linux code is supposed
to work on other platforms, but hasn't been tested yet.)

<p>
The <tt class="module">pty</tt> module defines the following functions:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3555' xml:id='l2h-3555' class="function">fork</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Fork. Connect the child's controlling terminal to a pseudo-terminal.
Return value is <code>(<var>pid</var>, <var>fd</var>)</code>. Note that the child 
gets <var>pid</var> 0, and the <var>fd</var> is <em>invalid</em>. The parent's
return value is the <var>pid</var> of the child, and <var>fd</var> is a file
descriptor connected to the child's controlling terminal (and also
to the child's standard input and output).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3556' xml:id='l2h-3556' class="function">openpty</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Open a new pseudo-terminal pair, using <tt class="function">os.openpty()</tt> if
possible, or emulation code for SGI and generic <span class="Unix">Unix</span> systems.
Return a pair of file descriptors <code>(<var>master</var>, <var>slave</var>)</code>,
for the master and the slave end, respectively.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3557' xml:id='l2h-3557' class="function">spawn</tt></b>(</nobr></td>
  <td><var>argv</var><big>[</big><var>, master_read</var><big>[</big><var>, stdin_read</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Spawn a process, and connect its controlling terminal with the current 
process's standard io. This is often used to baffle programs which
insist on reading from the controlling terminal.

<p>
The functions <var>master_read</var> and <var>stdin_read</var> should be
functions which read from a file-descriptor. The defaults try to read
1024 bytes each time they are called.
</dl>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="16.8 tty  "
  href="module-tty.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="16. unix Specific Services"
  href="unix.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="16.10 fcntl  "
  href="module-fcntl.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-tty.html">16.8 tty  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="unix.html">16. Unix Specific Services</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-fcntl.html">16.10 fcntl  </a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
